<template>
  <div class="app-container">
    <div class="my-padding" style="float: right">
      <el-button @click="$router.back()">返回</el-button>
    </div>
    <div style="padding-top: 1rem">
      <el-table
        id="myform"
        v-loading="listLoading"
        :data="list"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column label="打回人" align="center" prop="userName"/>
        <el-table-column label="打回时间" align="center" prop="createTime"/>
        <el-table-column label="原因" align="center" prop="message"/>
        <el-table-column label="阶段" align="center" prop="phase"/>

      </el-table>
    </div>

  </div>

</template>

<script>
  import $ from "@/api/project";

  export default {
    data() {
      return {
        value: "",
        state: 0,
        list: [],
        val: "",
        status: "",
        proName: "",
        listLoading: true,
        currentPage: 1,
        pageSize: 10,
        total: 0,
        options: [],
        statusList: [],
        form: {},
        rebackDialog: false,
        rebackReason: "",
        backId: "",
        backState: "",
      };
    },
    created() {
      this.find();
    },
    methods: {
      cancel() {
        this.rebackReason = ""
        this.rebackDialog = false
      },
      openBack(id, state) {
        this.backId = id
        this.backState = state
        this.rebackDialog = true
      },
      nextState(id, state) {
        $.updateProjectState({proId: id, status: state}).then(res => {
          this.find()
        })
      },
      reback() {
        let nowState = ""
        if (this.backState === "002") nowState = "0011"
        else if (this.backState === "004") nowState = "0031"
        else nowState = "0051"
        $.backProject({proId: this.backId, status: nowState, backReason: this.rebackReason}).then(res => {
          this.$message({
            type: 'success',
            message: '已驳回！'
          });
          this.cancel()
          this.find()
        })
      },
      addProject() {
        $.insertProject(this.form).then(res => {
          this.$router.push({
            path: "add",
            query: {proId: res.data}
          })
        })
      },
      find() {
        this.listLoading = true;
        $.findAllBackReasonById({
          proId: this.$route.query.proId
        }).then(
          response => {
            this.list = response.data;
            for (let argument of this.list) {
              switch (argument.status) {
                case "0011":
                  this.$set(argument, "phase", "发起未通过");
                  break;
                case "0041":
                  this.$set(argument, "phase", "结项未通过");
                  break;
                case "0051":
                  this.$set(argument, "phase", "成果申报失败");
                  break;
                case "008":
                  this.$set(argument, "phase", "不批准");
                  break;
              }
            }
            this.listLoading = false;
            console.log(this.list)
          }
        );
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 1;
        // console.log(this.currentPage)
        if (this.state == 1) {
          this.find(this.depId);
          //console.log(this.currentPage)
        } else this.find(this.depId);
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        //console.log(val)
        if (this.state == 1) {
          this.find(this.depId);
        } else this.find(this.depId);
      },

      handleEdit(id) {
        this.$router.push({
          path: "edit",
          query: {proId: id}
        });
      },
      handleFind(id) {
        this.$router.push({
          path: "find",
          query: {proId: id}
        });
      },

    }
  };
</script>
<style scoped>
  .button {
    padding-left: 1rem;
  }
</style>
